package java_class_work.week08.internet.upfile;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author Tiam
 * @Date 2022/11/1 14:31
 * @Description:
 */
public class TcpServer {
    public static void main(String[] args) {
        PrintWriter out = null;
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            Socket socket = serverSocket.accept();

            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
             out = new PrintWriter(socket.getOutputStream(),true);

            PrintWriter printWriter = new PrintWriter(new FileWriter(new File(".\\src\\java_class_work\\iotest\\a.txt")), true);

            // DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
            // long time = dataInputStream.readLong();

            String line = null;
            while ((line=in.readLine())!=null){
                // if(line.equalsIgnoreCase(time+"")) break;
                printWriter.println(line);
            }

            out.println("文件上传成功");
            socket.close();
            serverSocket.close();
        } catch (IOException e) {
            out.println("失败");
            e.printStackTrace();
        }
    }
}
